/* @(#)GSBusOrderRefundDetailAction.java    V0.1
 *
 * Project: GSdevelop
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;

import com.hitrust.gs.bean.GSOrderBean;
import com.hitrust.gs.business.GSOrderProcessor;
import com.hitrust.gs.dao.GSOrderDAO;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;

/**
 * 	退货管理
 */
public class GSBusOrderRefundDetailAction extends GSBaseAction {

    /* (non-Javadoc)
     * @see com.hitrust.gs.service.GSBaseAction#execute(com.hitrust.gs.service.GSBaseForm)
     */
    public String execute(GSBaseForm aForm) throws Exception 
    {
        
        String tOrderIdOrderDetailId = aForm.getRequest().getParameter("orderId");
        String tOrderDetailId=tOrderIdOrderDetailId.substring(0,tOrderIdOrderDetailId.indexOf(","));
        String tOrderId=tOrderIdOrderDetailId.substring(tOrderIdOrderDetailId.indexOf(",")+1,tOrderIdOrderDetailId.indexOf("."));
        
        try 
        {
            GSOrderProcessor tGSOrderProc = new GSOrderProcessor();
            //由订单编号查询订单及所订产品明细
            ArrayList tList = tGSOrderProc.getOrderDetailOfBusRefund(tOrderId);
            if(tList.size() > 0)
            {
                for(int i=0; i<tList.size(); i++)
                {
                    String[] tStr = (String[])tList.get(i);
                    GSLogWriter.debug(this,"tStr[0]=" + tStr[0]);
                    if(tStr[0].equals(tOrderDetailId))
                    {
                        //取出当前被选中订单明细单独传给页面
                        aForm.getRequest().setAttribute("curorderdetail",tStr);
                        tList.remove(i);
                        break;
                    }
                }
            }
            aForm.getRequest().setAttribute("ordermanufacture", tList);   
			
			//由订单编号查询退货订单及所订产品明细
			ArrayList tListRefund = tGSOrderProc.getRefundOrderDetail(tOrderDetailId);
			//取出当前被选中订单的退货明细单独传给页面
			if (tListRefund.size() > 0)
			{
				aForm.getRequest().setAttribute("orderrefunddetail",tListRefund);
			} 
                     
            GSOrderDAO tOrderDAO = new GSOrderDAO();
            
            //由订单编号查询订单信息
            GSOrderBean tBean = tOrderDAO.getOrderByTempID(tOrderId);
            aForm.getRequest().setAttribute("orderbean", tBean);
         			
        }
        catch (Exception e) 
        {
            aForm.getRequest().setAttribute("action","/A155001.do");
            aForm.getRequest().setAttribute("window","true");
            throw e;
        }
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
